<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <title>生成插件图标</title>
  <style>
    body {
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
      max-width: 600px;
      margin: 40px auto;
      padding: 20px;
      background: #f5f5f5;
    }
    h1 { color: #333; }
    .preview {
      display: flex;
      gap: 20px;
      margin: 20px 0;
      padding: 20px;
      background: #fff;
      border-radius: 8px;
    }
    .preview-item {
      text-align: center;
    }
    .preview-item canvas {
      border: 1px solid #ddd;
      border-radius: 4px;
    }
    .preview-item p {
      margin-top: 8px;
      font-size: 12px;
      color: #666;
    }
    button {
      background: #07c160;
      color: #fff;
      border: none;
      padding: 12px 24px;
      border-radius: 8px;
      font-size: 16px;
      cursor: pointer;
      margin-right: 10px;
    }
    button:hover {
      background: #06ad56;
    }
    .instructions {
      margin-top: 20px;
      padding: 16px;
      background: #fff3cd;
      border-radius: 8px;
      font-size: 14px;
    }
    .instructions ol {
      margin: 10px 0 0 20px;
    }
  </style>
</head>
<body>
  <h1>📑 插件图标生成器</h1>
  
  <div class="preview">
    <div class="preview-item">
      <canvas id="icon16" width="16" height="16"></canvas>
      <p>16x16</p>
    </div>
    <div class="preview-item">
      <canvas id="icon48" width="48" height="48"></canvas>
      <p>48x48</p>
    </div>
    <div class="preview-item">
      <canvas id="icon128" width="128" height="128"></canvas>
      <p>128x128</p>
    </div>
  </div>

  <button onclick="downloadAll()">下载全部图标</button>

  <div class="instructions">
    <strong>使用说明：</strong>
    <ol>
      <li>点击「下载全部图标」按钮</li>
      <li>将下载的 3 个 PNG 文件移动到 <code>icons/</code> 文件夹中</li>
      <li>重新加载扩展程序即可</li>
    </ol>
  </div>

  <script>
    // 绘制图标
    function drawIcon(canvas, size) {
      const ctx = canvas.getContext('2d');
      const padding = size * 0.1;
      const innerSize = size - padding * 2;
      
      // 背景 - 微信绿色圆角矩形
      ctx.fillStyle = '#07c160';
      const radius = size * 0.2;
      roundRect(ctx, 0, 0, size, size, radius);
      ctx.fill();
      
      // 文档图标
      ctx.fillStyle = '#fff';
      const docWidth = innerSize * 0.6;
      const docHeight = innerSize * 0.75;
      const docX = (size - docWidth) / 2;
      const docY = (size - docHeight) / 2;
      
      // 文档主体
      ctx.beginPath();
      ctx.moveTo(docX, docY + size * 0.08);
      ctx.lineTo(docX + docWidth - size * 0.12, docY);
      ctx.lineTo(docX + docWidth, docY + size * 0.12);
      ctx.lineTo(docX + docWidth, docY + docHeight);
      ctx.lineTo(docX, docY + docHeight);
      ctx.closePath();
      ctx.fill();
      
      // 折角
      ctx.fillStyle = '#d4f5e2';
      ctx.beginPath();
      ctx.moveTo(docX + docWidth - size * 0.12, docY);
      ctx.lineTo(docX + docWidth - size * 0.12, docY + size * 0.12);
      ctx.lineTo(docX + docWidth, docY + size * 0.12);
      ctx.closePath();
      ctx.fill();
      
      // 横线（文字占位）
      if (size >= 48) {
        ctx.fillStyle = '#07c160';
        const lineHeight = size * 0.03;
        const lineWidth = docWidth * 0.6;
        const lineX = docX + (docWidth - lineWidth) / 2;
        const lineSpacing = size * 0.08;
        
        for (let i = 0; i < 3; i++) {
          const lineY = docY + docHeight * 0.35 + i * lineSpacing;
          ctx.fillRect(lineX, lineY, lineWidth, lineHeight);
        }
      }
    }
    
    // 绘制圆角矩形
    function roundRect(ctx, x, y, width, height, radius) {
      ctx.beginPath();
      ctx.moveTo(x + radius, y);
      ctx.lineTo(x + width - radius, y);
      ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
      ctx.lineTo(x + width, y + height - radius);
      ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
      ctx.lineTo(x + radius, y + height);
      ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
      ctx.lineTo(x, y + radius);
      ctx.quadraticCurveTo(x, y, x + radius, y);
      ctx.closePath();
    }
    
    // 初始化
    const sizes = [16, 48, 128];
    sizes.forEach(size => {
      const canvas = document.getElementById(`icon${size}`);
      drawIcon(canvas, size);
    });
    
    // 下载单个图标
    function downloadIcon(size) {
      const canvas = document.getElementById(`icon${size}`);
      const link = document.createElement('a');
      link.download = `icon${size}.png`;
      link.href = canvas.toDataURL('image/png');
      link.click();
    }
    
    // 下载所有图标
    function downloadAll() {
      sizes.forEach((size, index) => {
        setTimeout(() => downloadIcon(size), index * 300);
      });
    }
  </script>
</body>
</html>

